package net.sycu.guomy.ems.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TestServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
		out.println("<HTML>");
		out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");
		out.println("  <BODY>");

		Enumeration names = request.getParameterNames();
		while (names.hasMoreElements()) {
			Object obj = names.nextElement();
			out.println(obj.toString() + " : " + request.getParameter(obj.toString()) + "<br>");
		}
		
		names = request.getHeaderNames();
		while (names.hasMoreElements()) {
			Object obj = names.nextElement();
			out.println(obj.toString() + " : " + request.getHeader(obj.toString()) + "<br>");
		}

		out.println(request.getAuthType() + "  <br>");	//
		out.println(request.getCharacterEncoding() + "  <br>");	// 
		out.println(request.getContentLength() + "  <br>");	// 
		out.println(request.getContentType() + "  <br>");	// 
		out.println(request.getLocalAddr() + "  <br>");	// 
		out.println(request.getLocalName() + "  <br>");	// 
		out.println(request.getLocalPort() + "  <br>");	// 
		out.println(request.getMethod() + "  <br>");	// 
		out.println(request.getPathInfo() + "  <br>");	// 
		out.println(request.getPathTranslated() + "  <br>");	// 
		out.println(request.getProtocol() + "  <br>");	// 
		out.println(request.getRemoteAddr() + "  <br>");	// 
		
		out.println("  </BODY>");
		out.println("</HTML>");
		out.flush();
		out.close();
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
